package com.sangeng.controller;

import com.sangeng.domain.core.ResponseResult;
import com.sangeng.domain.dto.UserInsertDto;
import com.sangeng.domain.dto.UserListDto;
import com.sangeng.domain.dto.UserUpdateDto;
import com.sangeng.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/user")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @GetMapping("/list")
    public ResponseResult list(UserListDto userListDto){
        return userService.listUsers(userListDto);
    }

    @PostMapping
    public ResponseResult insertUser(@RequestBody UserInsertDto userInsertDto){
        return userService.registerAdminUser(userInsertDto);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteById(@PathVariable Long id){
        return userService.removeUserById(id);
    }

    @GetMapping("/{id}")
    public ResponseResult getUserById(@PathVariable Long id){
        return userService.getUserRolesById(id);
    }

    @PutMapping
    public ResponseResult updateUser(@RequestBody UserUpdateDto userUpdateDto){
        return userService.updateUser(userUpdateDto, false);
    }

    @PutMapping("/changeStatus")
    public ResponseResult changeStatus(@RequestBody UserUpdateDto userUpdateDto){
        return userService.updateUser(userUpdateDto, true);
    }
}
